package edu.towson.cis.cosc490.examples.mapmyrun;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class DeployActivity extends Activity{
	private SharedPreferences prefs;
	private Intent serviceIntent;
	private final int NOTIFICATION_ID = 1;
	private NotificationManager notificationManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.deployidpage);
		// get preferences
		prefs = getSharedPreferences("Prefs", MODE_PRIVATE);
		serviceIntent = new Intent(this, MapMyRunService.class);

		EditText editText = (EditText) findViewById(R.id.deployId);
		editText.setOnEditorActionListener(new OnEditorActionListener() {
			@Override
			public boolean onEditorAction(TextView v, int actionId,
					KeyEvent event) {
				boolean handled = false;
				if (actionId == EditorInfo.IME_ACTION_GO) {
					startActivity(new Intent(getApplicationContext(), EventActivity.class));
					handled = true;
				}
				return handled;
			}
		});
	}
	
	
	public void createEvent(View v){
		
		
	}


	private void startNotification() {
		notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		Intent notificationIntent = new Intent(this, DeployActivity.class)
				.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		int flags = PendingIntent.FLAG_UPDATE_CURRENT;
		PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
				notificationIntent, flags);

		int icon = R.drawable.ic_launcher;
		Notification notification = new NotificationCompat.Builder(
				getApplicationContext()).setSmallIcon(icon)
				.setTicker(getText(R.string.app_name))
				.setContentTitle(getText(R.string.app_name))
				.setContentText(getText(R.string.content_text))
				.setContentIntent(pendingIntent).build();

		notificationManager.notify(NOTIFICATION_ID, notification);
	}

	private void stopNotification() {
		if (notificationManager != null) {
			notificationManager.cancel(NOTIFICATION_ID);
		}
	}
}